Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

228
Visualizações
TypeScript Err: "El elemento tiene implícitamente un tipo 'cualquiera' porque la expresión de tipo 'cualquiera' no se puede usar para indexar el tipo

[¡Hola!][1]

Recibo este error de TypeScript { "El elemento tiene implícitamente un tipo 'cualquiera' porque la expresión de tipo 'cualquiera' no se puede usar para indexar el tipo '{ 0: { imagen: cadena; título: cadena; texto: cadena; } ; 1: { imagen: cadena; título: cadena; texto: cadena; }; 2: { imagen: cadena; título: cadena; texto: cadena; }; }'.", }. TS7053

¿No está seguro de dónde se deben agregar mis interfaces o si es necesario?

esto está resaltado setCurrent(carouselData[event.target.getAttribute("data-Testimonios")])

a qué cambiarlos. No tengo idea de dónde me estoy equivocando, ya que solo he estado codificando durante un mes.

Mi código para un carrusel :

 interface CarouselCardProperties { image: string; title: string; text: string; } export default function Testimonials() { const carouselData = { 0: { image: tobi, title: "I no longer have to howl at the moon to call for my lady !!", text: "Tobi ~ Vancouver, Canada", }, 1: { image: girly, title: "With Enrico going on dates, we have more time to ourselves!", text: " Gina ~ Rome, Italy", }, 2: { image: loveshades, title: "I no longer have to worry about staying clean, I kitties licking me every night. I have Love Shades on.", text: " Princess ~ Georgia, USA", }, }; const [current, setCurrent] = useState(carouselData[0]) const [active, setActive] = useState(0) const handleSetClick = (event:any) => { setCurrent(carouselData[event.target.getAttribute("data-Testimonials")]) setActive(event.target.getAttribute("data-Testimonials")) }; return ( <Container> <Img src={current.image} /> <Title>{current.title}</Title> <Text>{current.text}</Text> <div> {Object.keys(carouselData).map(index => ( <Span onClick={(event:any) => handleSetClick(event)} data-Testimonials={index} key={index} /> ))} </div> </Container> ) }``` [1]: https://i.stack.imgur.com/A9CwZ.png
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

¿Por qué necesita un atributo data-Testimonials ?

Simplemente pase directamente el índice a handleSetClick :

 const handleSetClick = (index: keyof typeof carouselData) => { setCurrent(carouselData[index]) setActive(index) }; return ( <Container> <Img src={current.image} /> <Title>{current.title}</Title> <Text>{current.text}</Text> <div> {Object.keys(carouselData).map(index => ( <Span onClick={() => handleSetClick(index)} key={index} /> ))} </div> </Container> )
about 4 years ago · Juan Pablo Isaza Relatório

0

El código

 const carouselData = { 0: { // ... } }

define los datos de carouselData para usar índices numéricos, pero los indexa con event.target.getAttribute("data-Testimonials") , que implícitamente tiene cualquier tipo. Escribiría fuertemente su parámetro de event , por lo que event.target.getAttribute("data-Testimonials") tiene un tipo de cadena. Luego redefiniría carouselData para usar índices de cadenas así:

 const carouselData = { '0': { // ... }, '1': { // ... } }

En general, es mejor evitar any tipo siempre que sea posible para evitar este tipo de situaciones.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda